#include "widget.h"
#include "ui_widget.h"
#include <QDateTime>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
}

Widget::~Widget()
{
    delete ui;
}

void Widget::on_pushButton_clicked()
{
    QDateTime dt = QDateTime::currentDateTime();
    ui->timeEdit->setTime(dt.time());
    ui->editTime->setText(dt.toString("hh:mm:ss"));
    ui->dateEdit->setDate(dt.date());
    ui->editDate->setText(dt.toString("yyyy-MM-dd"));
    ui->dateTimeEdit->setDateTime(dt);
    ui->editDateTime->setText(dt.toString("yyyy-MM-dd hh:mm:ss"));

}


void Widget::on_pushButton_2_clicked()
{
    QString str = ui->editTime->text();
    str = str.trimmed();
    if(!str.isEmpty()){
        QTime datetime = QTime::fromString(str, "hh:mm:ss");
        ui->timeEdit->setTime(datetime);
    }
}


void Widget::on_pushButton_3_clicked()
{
    QString str = ui->editDate->text();
    str = str.trimmed();
    if(!str.isEmpty()){
        QDate datetime = QDate::fromString(str, "yyyy-MM-dd");
        ui->dateEdit->setDate(datetime);
    }
}


void Widget::on_pushButton_4_clicked()
{
    QString str = ui->editDateTime->text();
    str = str.trimmed();
    if(!str.isEmpty()){
        QDateTime datetime = QDateTime::fromString(str, "yyyy-MM-dd hh:mm:ss");
        ui->dateTimeEdit->setDateTime(datetime);
    }
}

